package com.yuncheng.oaApi.controller;

import java.util.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.oaApi.entity.*;
import com.yuncheng.oaApi.service.*;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.utils.I18nUtil;
import com.yuncheng.common.base.controller.BaseController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description: 流程页面
 * @Author: yuncheng
 * @Date: 2023-10-12
 * @Version: V1.0
 */
@Api(tags = "流程页面接口")
@RestController
@RequestMapping("/api/spzx-oa/sysFlowPage")
public class SysFlowPageController extends BaseController<OaSysFlowPage, IOaSysFlowPageService> {

    private static final Logger log = LoggerFactory.getLogger(SysFlowPageController.class);

    @Resource
    private IOaSysFlowPageService sysFlowPageService;



    /**
     * 分页列表查询
     *
     * @param oaSysFlowPage
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "流程页面-分页列表查询")
    @ApiOperation(value = "流程页面-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(OaSysFlowPage oaSysFlowPage, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {

        LambdaQueryWrapper<OaSysFlowPage> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
        objectLambdaQueryWrapper.like(StringUtils.isNotBlank(oaSysFlowPage.getFymmc()), OaSysFlowPage::getFymmc, oaSysFlowPage.getFymmc()); //页面名称
        objectLambdaQueryWrapper.like(StringUtils.isNotBlank(oaSysFlowPage.getFywlx()), OaSysFlowPage::getFywlx, oaSysFlowPage.getFywlx()); //业务类型

        objectLambdaQueryWrapper.orderByAsc(OaSysFlowPage::getFxh);

        Page<OaSysFlowPage> page = new Page<>(pageNo, pageSize);
        IPage<OaSysFlowPage> pageList = sysFlowPageService.page(page, objectLambdaQueryWrapper);
        return HttpResult.ok(pageList);
    }



    /**
     * 添加
     *
     * @param oaSysFlowPage
     * @return
     */
    @AutoLog(value = "流程页面-添加")
    @ApiOperation(value = "流程页面-添加")
    //@RequiresPermissions("sysFlowPageObj:SysFlowPage:add")
    @PostMapping(value = "/add")
    public HttpResult<?> add(@RequestBody OaSysFlowPage oaSysFlowPage) {
        HttpResult<String> result = new HttpResult(true);
        sysFlowPageService.save(oaSysFlowPage);
        result.setResult(oaSysFlowPage.getId());
        result.setMessage(I18nUtil.message("save.success"));
        return result;
    }

    /**
     * 编辑
     *
     * @param oaSysFlowPage
     * @return
     */
    @AutoLog(value = "流程页面-编辑")
    @ApiOperation(value = "流程页面-编辑")
    //@RequiresPermissions("sysFlowPageObj:SysFlowPage:edit")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody OaSysFlowPage oaSysFlowPage) {
        sysFlowPageService.updateById(oaSysFlowPage);
        return HttpResult.ok(I18nUtil.message("update.success"));
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "流程页面-通过id删除")
    @ApiOperation(value = "流程页面-通过id删除")
    //@RequiresPermissions("sysFlowPageObj:SysFlowPage:delete")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam("id") String id) {
        sysFlowPageService.removeById(id);
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "流程页面-批量删除")
    @ApiOperation(value = "流程页面-批量删除")
    //@RequiresPermissions("sysFlowPageObj:SysFlowPage:delete")
    @DeleteMapping(value = "/deleteBatch")
    public HttpResult<?> deleteBatch(@RequestParam("ids") String ids) {
        sysFlowPageService.removeByIds(Arrays.asList(ids.split(",")));
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "流程页面-通过id查询")
    @ApiOperation(value = "流程页面-通过id查询")
    @GetMapping(value = "/queryById")
    public HttpResult<?> queryById(@RequestParam("id") String id) {
        OaSysFlowPage oaSysFlowPage = sysFlowPageService.getById(id);
        return HttpResult.ok(oaSysFlowPage);
    }

    /**
     *@param jobId
     * @return
     */
    @AutoLog(value = "流程页面表-通过jobid查询")
    @ApiOperation(value = "流程页面表-通过jobid查询")
    @GetMapping(value = "/queryByJodId")
    public HttpResult<?> queryByJodId(String jobId,String lcmbbm,String fpid) {
        Map map = sysFlowPageService.byJodId(jobId, lcmbbm, fpid);
        return HttpResult.ok(map);
    }


    /**
     * 获取节点list
     */

    @AutoLog(value = "获取节点list")
    @ApiOperation(value = "获取节点list")
    @GetMapping(value = "/pidgetlchj")
    public HttpResult<?> pidgetlchj(String pid) {
        List pidgetlchj = sysFlowPageService.pidgetlchj(pid);
        return HttpResult.ok(pidgetlchj);
    }

    /**
     * 修改待办申请时间
     */
    @AutoLog(value = "修改待办申请时间")
    @ApiOperation(value = "修改待办申请时间")
    @GetMapping(value = "/updatesqsj")
    public HttpResult<?> updatesqsj(String pid,String sqsj) {
        sysFlowPageService.updatesqsj(pid,sqsj);
        return HttpResult.ok("修改成功");
    }

}
